// components/custom-tab-bar.ts
import { hideModuleConfigAPI } from "../api/open";
Component({
  /**
   * 组件的属性列表
   */
  properties: {},

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    tabList: [
      {
        path: "/pages/index/index",
        text: "首页",
        iconPath: "/static/images/index/tab_home0.png",
        selectedIconPath: "/static/images/index/tab_home1.png",
      },
      {
        path: "/pages/monitor/monitor",
        text: "监控",
        iconPath: "/static/images/index/tab_monitor0.png",
        selectedIconPath: "/static/images/index/tab_monitor1.png",
      },
      // hide shiye
      {
        path: "/pages/shiye/shiye",
        text: "师爷大模型",
        iconPath: "/static/images/index/tab_ai.png",
        selectedIconPath: "/static/images/index/tab_ai.png",
        className: "tab-ai",
      },
      {
        path: "/pages/propertyClue/propertyClue",
        text: "财产线索",
        iconPath: "/static/images/index/tab_clue0.png",
        selectedIconPath: "/static/images/index/tab_clue1.png",
      },
      {
        path: "/pages/mine/mine",
        text: "我的",
        iconPath: "/static/images/index/tab_mine0.png",
        selectedIconPath: "/static/images/index/tab_mine1.png",
      },
    ],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onchange(e: any) {
      const index = e.currentTarget.dataset.index;
      const path = e.currentTarget.dataset.path;
      this.setData({
        active: index,
      });
      wx.switchTab({
        url: path,
      });
    },
    async hideModule() {
      const res: {
        code: string;
        content: string[];
        desc: string;
        timestamp: number;
      } = await hideModuleConfigAPI("app");
      if (
        res.code === "000" &&
        res.content &&
        res.content.length > 0 &&
        res.content.includes("tabShiYe")
      ) {
        this.setData({
          tabList: this.data.tabList.filter(
            (item) => item.className !== "tab-ai"
          ),
        });
      }
    },
  },
  //生命周期函数
  lifetimes: {
    created() {
      this.hideModule();
    },
    attached() {},
    ready() {},
    moved() {},
    detached() {},
    error() {},
  },
  //组件所在页面的生命周期
  pageLifetimes: {
    show() {},
    hide() {},
    resize() {},
  },
});
